<!--
  ~ Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
    
<div class="dt-list">
    <div data-ng-if="valueObjRef.length > 0" data-ng-repeat="i in getNumber(valueObjRef.length) track by $index" class="dt-list-item">
        <span class="delete-dt-list-item" data-ng-click="deleteListItem($index)"></span>
        <div data-ng-if="isSchemaTypeDataType">
            <fields-structure value-obj-ref="valueObjRef[$index]"
                            type-name="schemaProperty.type"
                            parent-form-obj="parentFormObj"
                            parent-property="parentProperty"
                            component-instance-map="componentInstanceMap"
                            fields-prefix-name="fieldsPrefixName+''+$index"
                            types="types"
                            is-service="isService"
                            complex-toscapath="$index"
                            read-only="readOnly"></fields-structure>
        </div>
        <div data-ng-if="!isSchemaTypeDataType">
            <div class="i-sdc-form-item list-new-item" data-ng-class="{error:(parentFormObj['listNewItem'+fieldsPrefixName].$dirty && parentFormObj['listNewItem'+fieldsPrefixName].$invalid)}"
                ng-if="schemaProperty.type !== 'map'">
                <form class="temp-form" data-ng-if="isService && complexToscapath == null">
                    <input type="radio" name="hasToscaFunction-{{fieldsPrefixName}}-{{$index}}" data-ng-checked="{{showToscaFunction[$index] == false}}" data-ng-click="onEnableTosca(false,$index)"/> 
                    Value
                    <input type="radio" name="hasToscaFunction-{{fieldsPrefixName}}-{{$index}}" data-ng-checked="{{showToscaFunction[$index]}}" data-ng-click="onEnableTosca(true,$index)" /> 
                    {{'TOSCA_FUNCTION_LABEL' | translate}}
                </form>
                <input class="i-sdc-form-input"
                    data-tests-id="listNewItem{{fieldsPrefixName}}"
                    ng-if="!constraints && !((schemaProperty.simpleType||schemaProperty.type) == 'boolean') && !showToscaFunction[$index]"
                    data-ng-disabled="readOnly"
                    data-ng-model="valueObjRef[$index]"
                    type="text"
                    name="listNewItem{{fieldsPrefixName}}"
                    data-ng-pattern="getValidationPattern((schemaProperty.simpleType||schemaProperty.type))"
                    data-ng-change="addValueToList(valueObjRef[$index], $index);$event.stopPropagation();"
                    data-ng-model-options="{ debounce: 200 }"
                    data-ng-maxlength="maxLength"
                    maxlength="{{maxLength}}"
                    data-required
                    autofocus />
                <select class="i-sdc-form-select"
                        data-tests-id="listNewItem{{fieldsPrefixName}}"
                        ng-if="!constraints && (schemaProperty.simpleType||schemaProperty.type) == 'boolean' && !showToscaFunction[$index]"
                        data-ng-disabled="readOnly"
                        name="listNewItem{{fieldsPrefixName}}"
                        data-ng-model="valueObjRef[$index]">
                    <option value="true">true</option>
                    <option value="false">false</option>
                </select>

                <div data-ng-if="showToscaFunction[$index]" class="div-tosca-function">
                    <tosca-function [property]="parentProperty"
                                    [component-instance-map]="componentInstanceMap"
                                    [allow-clear]="false"
                                    [composition-map]="true"
                                    [composition-map-key]="$index+''"
                                    (on-valid-function)="onGetToscaFunction($event,$index)"
                    >
                    </tosca-function>
                </div>
    
                <select class="i-sdc-form-select"
                    data-tests-id="constraints"
                    ng-if="constraints"
                    data-ng-disabled="readOnly"
                    data-ng-model="valueObjRef[$index]">
                    <!-- Get the default value in case exist -->
                    <option value = "{{listNewItem.value}" name = "{{listNewItem.value}}" hidden selected>
                            {{listNewItem.value}}
                    </option> 
                    <!-- add all constratint to Select list -->
                    <option ng-repeat='value in constraints' value="{{value}}" name="{{value}}">
                        {{value}}
                    </option>
                    
                    
                </select>
    
                <div class="input-error" data-ng-show="parentFormObj['listNewItem'+fieldsPrefixName].$dirty && parentFormObj['listNewItem'+fieldsPrefixName].$invalid">
                    <span ng-show="parentFormObj['listNewItem'+fieldsPrefixName].$error.pattern" translate="PROPERTY_EDIT_PATTERN"></span>
                    <span ng-show="parentFormObj['listNewItem'+fieldsPrefixName].$error.maxlength" translate="VALIDATION_ERROR_MAX_LENGTH" translate-values="{'max': '{{maxLength}}' }"></span>
                </div>
            </div>
            <div ng-if="schemaProperty.type === 'map'">
                <type-map value-obj-ref="value"
                            schema-property="stringSchema"
                            parent-form-obj="parentFormObj"
                            fields-prefix-name="fieldsPrefixName+''+$index"
                            read-only="readOnly"
                            default-value="{{undefined}}"
                            max-length="maxLength"
                            show-add-btn="true"
                            constraints="constraints">
                </type-map>
            </div>
        </div>
    </div>
    <div class="add-btn add-list-item" data-tests-id="add-list-item"
                data-ng-class="{'disabled': readOnly}" data-ng-click="listNewItem.value='';addListItem();">Add</div>
</div>

